package modules.hero.view.component
{
	import com.hobbit.analyze.AssetsManager;
	import com.hobbit.analyze.base.LoadItem;
	import com.hobbit.ui.data.UiLayoutData;
	import com.hobbit.ui.managers.UiManager;
	
	import feathers.controls.Button;
	import feathers.core.PopUpManager;
	
	import flash.utils.Dictionary;
	
	import modules.hero.HeroContext;
	
	import org.robotlegs.core.IInjector;
	import org.robotlegs.utilities.modular.core.IStarlingModule;
	import org.robotlegs.utilities.modular.core.IStarlingModuleContext;
	
	import shell.config.ConfigManager;
	
	import starling.core.Starling;
	import starling.display.MovieClip;
	import starling.display.Sprite;
	import starling.events.Event;
	import starling.events.TouchEvent;
	import starling.textures.TextureAtlas;
	
	public class HeroModule extends Sprite implements IStarlingModule
	{
		protected var context:IStarlingModuleContext;
		
		private var btn:Button;
		
		public function HeroModule()
		{
			super();
//			btn = new Button();
//			btn.label = "remove me";
//			addChild(btn);
//			btn.addEventListener(Event.TRIGGERED, onBtnTrigger);
			
//			var textureAtlas:TextureAtlas = AssetsManager.getInstance().getSynPreloadRes("mat","",LoadItem.TYPE_SHEET);
//			var mc:MovieClip = new MovieClip(textureAtlas.getTextures(),12);
//			mc.x = Math.random()*600;
//			mc.y = Math.random()*600;
//			addChild(mc);
//			Starling.juggler.add(mc);
			
//			AssetsManager.getInstance().getMatRes("10003",onT,"HERO_SHEET",LoadItem.TYPE_SHEET);
//			function onT(data:Object):void
//			{
//				var mc:MovieClip = new MovieClip(data.getTextures(),15);
//				mc.x = Math.random()*600;
//				mc.y = Math.random()*600;
//				addChild(mc);
//				Starling.juggler.add(mc);
//			}
			
			var c:Dictionary = ConfigManager.getInstance().skillParser.getDic();
			var uiData:UiLayoutData = UiManager.getInstance().getData("TestPanel");
			
			PopUpManager.createPopUp(TestPanel);
			
		}
		
		private function onBtnTrigger(event:Event):void
		{
			event.currentTarget.removeEventListener(Event.TRIGGERED, onBtnTrigger);
			dispatchEvent(new Event("shutDown", true));
		}
		
		[Inject]
		public function set parentInjector(value:IInjector):void
		{
			context = new HeroContext(this, value);
		}
		
		public function destroy():void
		{
			removeFromParent(true);
			dispose();
			context.dispose();
			context = null;
		}
	}
}